home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / manchest.lha / MANCHESTER / usenet / st80_pre4 / CharacterComparing.st < prev    next >
Text File  |  1993-07-24  |  3KB  |  94 lines

  1. "    NAME        CharacterComparing
  2.     AUTHOR        Jan Steinman <jans@tekgvs.labs.tek.com>
  3.     FUNCTION    Add more magnitude funcitionality to Character
  4.     ST-VERSIONS    Tek 2.3.0
  5.     PREREQUISITES    
  6.     CONFLICTS    
  7.     DISTRIBUTION    world
  8.     VERSION        1.1
  9.     DATE        May 1988?
  10.     SUMMARY    
  11. So a Character is a Magnitude, and knows about '<' and '>', then it
  12. should be possible to have an Interval of Characters, right?  Well,
  13. sort of.  You can create the interval, all right, but you can't do
  14. much with it, because Intervals assume their objects can perform the
  15. arithmetic operations +, -, //, and \\.
  16.  
  17. The following methods add these capabilities to Characters, and allow
  18. a Character to make an interval with another Character, so you can
  19. enumerate over a range of Characters quickly and easily, or store a
  20. group of Characters in a compact form.  (The latter case is handy as a
  21. substitute for literals: ($0 to: $9) instead of '0123456789', or ($A
  22. to: $Z), ($a to: $z) as a substitute for, well, never mind.)  Also
  23. added is the capability to compare a Character with some other
  24. Magnitude.  This change is som [original text here lost - Ed]
  25. controversial, because Character = is a primitive, and is defined as identity, making equality among Magnitudes impossible.
  26.  
  27. Jan Steinman - N7JDB
  28. Tektronix Electronic Systems Laboratory
  29. Box 500, MS 50-370, Beaverton, OR 97077
  30. (w)503/627-5881 (h)503/657-7703
  31. "
  32. 'From Tektronix Smalltalk-80 version TB2.2.2a of May 05, 1988, 18:14:03.'!
  33.  
  34.  
  35. 'From Tektronix Smalltalk-80 version TB2.3.0 of Nov 13, 1987, 16:18:35. on 19 
  36. April 1988 at 4:00:47 pm'!
  37.  
  38.  
  39.  
  40. !Character methodsFor: 'arithmetic'!
  41.  
  42. + aMagnitude
  43.     "Return the Character that is <aMagnitude> higher than the receiver.  Wrap if the resulting value is not a legal Character value."
  44.  
  45.     ^self class value: self asInteger + aMagnitude asInteger \\ CharacterTable size!
  46.  
  47. - aMagnitude
  48.     "Return the Character that is <aMagnitude> lower than the receiver.  Wrap if the resulting value is not a legal Character value."
  49.  
  50.     ^self class value: self asInteger - aMagnitude asInteger \\ CharacterTable size!
  51.  
  52. // aMagnitude
  53.     "Return the Character who's value is the receiver divided by <aMagnitude>.  Wrap if the resulting value is not a legal Character value."
  54.  
  55.     ^self class value: self asInteger // aMagnitude asInteger \\ CharacterTable size!
  56.  
  57. \\ aMagnitude
  58.     "Return the Character who's value is the receiver modulo <aMagnitude>.  Wrap if the resulting value is not a legal Character value."
  59.  
  60.     ^self class value: self asInteger \\ aMagnitude asInteger \\ CharacterTable size! !
  61.  
  62. !Character methodsFor: 'comparing'!
  63.  
  64. < aMagnitude 
  65.     "Answer true if the receiver's value < aMagnitude's value."
  66.  
  67.     ^self asInteger < aMagnitude asInteger!
  68.  
  69. > aMagnitude 
  70.     "Answer true if the receiver's value > aMagnitude's value."
  71.  
  72.     ^self asInteger > aMagnitude asInteger! !
  73.  
  74. !Character methodsFor: 'converting'!
  75.  
  76. to: aMagnitude
  77.     "Return an Interval over the characters from the receiver to <aMagnitude>.  Wrap <aMagnitude> if it is not a legal Character value."
  78.  
  79.     ^Interval from: self to: aMagnitude \\ CharacterTable size! !
  80.  
  81. !Interval methodsFor: 'accessing'!
  82.  
  83. size
  84.     "Return an Integer count of the objects represented by this Interval."
  85.  
  86.     step < 0
  87.         ifTrue: [start < stop
  88.                 ifTrue: [^0]
  89.                 ifFalse: [^(stop - start // step + 1) asInteger]]
  90.         ifFalse: [stop < start
  91.                 ifTrue: [^0]
  92.                 ifFalse: [^(stop - start // step + 1) asInteger]]! !
  93.  
  94.